﻿
@{
    ViewBag.Title = "密码找回";
    Layout = "~/Views/Shared/_Login.cshtml";
}

<form id="dataForm">
    <div class="tc-panel-back"></div>
    <div class="tc-panel tc-register">
        <div class="tc-login-logo">
            <a href="/home/index@(ViewBag.Suffix)"><img src="~/Content/img/login_logo.png" alt="logo" /></a>
        </div>
        <div class="tc-login-option">
            <h1>找回</h1>
        </div>
        <div class="tc-login-option">
            <input type="text" name="phone" placeholder="手机号码" class="layui-input">
        </div>
        <div class="tc-login-option">
            <input type="text" name="smsCode" placeholder="短信验证码" class="layui-input tc-login-option-small">
            <a href="javascript:void(0)" class="tc-login-btn" id="sendSmsBtn" onclick="javascript: { reg.sendSms(); }">发送验证码</a>
        </div>
        <div class="tc-login-option">
            <input type="password" name="passWord" placeholder="密码" class="layui-input">
        </div>
        <div class="tc-login-option">
            <input type="password" name="passWord2" placeholder="重复密码" class="layui-input">
        </div>
        <div class="tc-login-option">
            <a href="/login/index@(ViewBag.Suffix)" class="tc-left">立即登录</a>
        </div>
        <div class="tc-login-option">
            <a class="layui-btn tc-login-w100" onclick="javascript: { reg.savaData(); }">找回</a>
        </div>
    </div>
</form>

<script>
    var reg = new Reg();

    function Reg() {
        this.option = {
            smsInterval: null,
            smsSpeed: 0
        };
        this.sendSms = function () {
            if (reg.option.smsSpeed == 0) {
                var paras = $('#dataForm').getForm();
                if (paras.phone.length != 11) {
                    layer.msg('手机号码长度为11位');
                    return;
                }
                $.post('/login/SendBackSms', paras, function (result) {
                    layer.msg('发送成功');
                    reg.option.smsSpeed = 120;
                    reg.option.smsInterval = setInterval(reg.sendSmsSpeed, 1000);
                });
            }
        };
        this.sendSmsSpeed = function () {
            if (reg.option.smsSpeed > 0) {
                reg.option.smsSpeed -= 1;
                $('#sendSmsBtn').html('发送验证码' + reg.option.smsSpeed + 'S');
            } else {
                window.clearInterval(reg.option.smsInterval);
            }
        };
        this.savaData = function () {
            var paras = $('#dataForm').getForm();
            if (paras.phone.length != 11) {
                layer.msg('手机号码长度为11位');
                return;
            }
            if (paras.passWord == '' || paras.smsCode == '') {
                layer.msg('请填写完整');
                return;
            }
            $.post('/login/UserBackPasswordResult', paras, function (result) {
                layer.msg('找回成功，正在加载中...');
                setTimeout(function () { window.location = '/login/index'; }, 1000);
            });
        };
    };
</script>